
import wx

from events import *

class Controller:
    
    def __init__(self, mediaSmool):
        self.__mediaSmool = mediaSmool
        self.__viewers = []
    
    def AddViewer(self, viewer):
        self.__viewers.append(viewer)
    
    def Rename(self, newName, fileItem, renameInLowercase, prefix = ""):
        fi = self.__mediaSmool.rename(newName, fileItem.GetId(), renameInLowercase, prefix)
        evt = Event(myEVT_FILE_RENAMED, 1)
        evt.SetValue(fi)
        self.__ProcessEvent(evt)
    
    def SetMediaDir(self, path):
        try:
            files = self.__mediaSmool.loadFiles(path)
            evt = Event(myEVT_FILES_LOADED, 1)
            evt.SetValue(files)
            self.__ProcessEvent(evt)
        except:
            pass
    
    def MoveToTrash(self, fileItem):
        self.__mediaSmool.moveToTrash(fileItem)
    
    def GetMediaDir(self):
        return self.__mediaSmool.getDir()
    
    def __ProcessEvent(self, event):
        for viewer in self.__viewers:
            viewer.AddPendingEvent(event)